const express=require('express')
const mysql=require('mysql')
const goods=express.Router()
const database=require('../database')
const db=mysql.createPool(database)
goods.use(express.json())
goods.use(express.urlencoded({ extended:false}))
goods.use(express.static('./'))
goods.post('/list',(req,res)=>{
    let sql="select * from t_goods"
    db.query(sql,[],(err,result)=>{
        if(result){
            res.send({
                    success:true,
                    msg:'成功',
                    list:result
            })
        }else{
            res.send({
                success:false,
                msg:'失败',
            })
        }
    })
})
goods.post('/getGoods',(req,res)=>{
    let sql="select * from t_goods where id=?"
    db.query(sql,[req.body.id],(err,goods)=>{
        if(goods.length){
            res.send({
           success:true,
           msg :'成功',
           goods:goods[0]
        })
        }else{
            res.send({
                success:false,
                msg:'失败'
            })
        }
    })
})
module.exports=goods